package com.ruoyi.project.bas.productMap.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.bas.productMap.domain.ProductMap;
import com.ruoyi.project.bas.productMap.service.IProductMapService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料对应关系Controller
 * 
 * @author ruoyi
 * @date 2024-01-26
 */
@Controller
@RequestMapping("/bas/productMap")
public class ProductMapController extends BaseController
{
    private String prefix = "bas/productMap";

    @Autowired
    private IProductMapService productMapService;

    @GetMapping()
    public String productMap()
    {
        return prefix + "/productMap";
    }

    /**
     * 查询物料对应关系列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductMap productMap)
    {
        startPage();
        List<ProductMap> list = productMapService.selectProductMapList(productMap);
        return getDataTable(list);
    }

    /**
     * 导出物料对应关系列表
     */
    @Log(title = "物料对应关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductMap productMap)
    {
        List<ProductMap> list = productMapService.selectProductMapList(productMap);
        ExcelUtil<ProductMap> util = new ExcelUtil<ProductMap>(ProductMap.class);
        return util.exportExcel(list, "物料对应关系数据");
    }

    /**
     * 新增物料对应关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物料对应关系
     */
    @Log(title = "物料对应关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductMap productMap)
    {
        return toAjax(productMapService.insertProductMap(productMap));
    }

    /**
     * 修改物料对应关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ProductMap productMap = productMapService.selectProductMapById(id);
        mmap.put("productMap", productMap);
        return prefix + "/edit";
    }

    /**
     * 修改保存物料对应关系
     */
    @Log(title = "物料对应关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductMap productMap)
    {
        return toAjax(productMapService.updateProductMap(productMap));
    }

    /**
     * 删除物料对应关系
     */
    @Log(title = "物料对应关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productMapService.deleteProductMapByIds(ids));
    }
}
